<?php

namespace Alipay\AlipayAuth\Response;

use Alipay\Http\Response;

class AlipayAuthISVInviteQueryResponse extends Response {

    protected $msg;

    protected $signList = [];

    protected $userId = '';

    public function resolve(): Response
    {
        parent::resolve();

        if (json_decode($this->getBody())) {
            $body = json_decode($this->getBody(), true);
            $this->setBody($body);
            $this->sign = $body['sign'] ?? '';
            $body = $body['alipay_open_invite_order_query_response'] ?? '';
            $code = $body['code'] ?? '';
            $this->msg = $body['msg'] ?? '';

            if ($code != '10000') {
                $this->setError(trim($this->msg . ' ' . ($body['sub_code'] ?? '') . ' ' . ($body['sub_msg'] ?? '')));
                return  $this;
            }
            $this->userId = $body['merchant_pid'] ?? '';
            $this->signList = $body['sign_status_list'] ?? [];

        } else {
            $this->setError($this->getBody());
        }

        return $this;
    }

    /**
     * @return array
     */
    public function getSignList(): array
    {
        return $this->signList;
    }

    /**
     * @return string
     */
    public function getUserId(): string
    {
        return $this->userId;
    }

}
